package com.lenovo.weaver;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import core.lib.common.interfaces.agent.SocketAgent;

public class JavaNetwork implements SocketAgent
{
	Socket socket;
	InputStream in;
	OutputStream out;

	public JavaNetwork()
	{

	}

	@Override
	public void open(String address, int port)
	{
		try
		{
			socket = new Socket(address, port);
			in = socket.getInputStream();
			out = socket.getOutputStream();
		}
		catch (IOException e)
		{
		}
	}

	@Override
	public InputStream getInputStream()
	{
		return in;
	}

	@Override
	public OutputStream getOutputStream()
	{
		return out;
	}

	@Override
	public void close() throws IOException
	{
		try
		{
			if (in != null)
			{
				in.close();
				in = null;
			}
			if (out != null)
			{
				out.close();
				out = null;
			}
		}
		catch (IOException e)
		{
		}
		finally
		{
			in = null;
			out = null;
		}
	}
}